using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Stickers.Web;
using Stickers.Web.Utilities;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddTransient<StickersMessageHandler>();

if (builder.HostEnvironment.IsDevelopment())
{
    builder.Services.AddHttpClient("stickersHttpClient", client => client.BaseAddress = new Uri("http://localhost:5141/"))
        .AddHttpMessageHandler<StickersMessageHandler>();
}
else
{
    builder.Services.AddHttpClient("stickersHttpClient",
            client => client.BaseAddress = new Uri(new Uri(builder.HostEnvironment.BaseAddress), "api/"))
        .AddHttpMessageHandler<StickersMessageHandler>();
}

builder.Services.AddOidcAuthentication(options =>
{
    builder.Configuration.Bind("Local", options.ProviderOptions);
});


builder.Services.AddBlazorBootstrap();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddAuthorizationCore();
await builder.Build().RunAsync();